<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="../../common/layui.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
</head>
<body>
<!-- 弹出页 -->
<form class="layui-form" id="model" style="padding-top: 10px;">
    <!-- 隐藏属性 -->
    <input id="load" type="hidden" name="load" value="${load}"/>
    <input id="id" type="hidden" name="id" value="${model.id}"/>
    <!-- 内容 -->
    <div class="manage_text2">

        <div class="layui-form-item manage-form-item" id="parent">
            <label class="layui-form-label manage_text_bt"><span>上级菜单</span></label>
            <input type="hidden" id="parentId" name="parentId" value="${parent.id}"/>
            <input class="layui-input newsName manage_text_input" id="parentName" name="parentName" value="${parent.name}"/>
        </div>

        <div class="layui-form-item manage-form-item">
            <label class="layui-form-label manage_text_bt"><span>菜单名称</span><i>*</i></label>
            <input class="layui-input newsName manage_text_input" id="name" name="name" value="${model.name}"/>
        </div>


        <div class="layui-form-item manage-form-item">
            <label class="layui-form-label manage_text_bt"><span>菜单地址</span><i>*</i></label>
            <input class="layui-input newsName manage_text_input" id="url" name="name" value="${model.url}"/>
        </div>

        <div class="layui-form-item manage-form-item">
            <label class="layui-form-label manage_text_bt"><span>备注</span></label>
            <textarea class="layui-input newsName manage_text_input" style="height: 80px;" id="other"  name="other">${model.other}</textarea>
        </div>

    </div>
</form>

<script type="text/javascript">
    $(function () {
        var load = $("#load").val();
        var parentId = $("#parentId").val();
        if(!parentId){
            $("#parent").hide();
        }
        if ("detail" == load) {//是查看
            $("input,textarea,select").attr("readonly", "readonly");
        } else {
            $("input,textarea,select").removeAttr("readonly");
            $("#parentId,#parentName").attr("readonly", "readonly");
        }
    });

    /**添加或者修改的方法*/
    function saveOrUpdate() {
        if (checkForm() == false) {
            return false;
        }
        var res = false;
        $.ajax({
            url: "menu/opt",
            type: "post",
            cache: false,
            async: false,
            data: $("#model").serialize(),
            dataType: "json",
            success: function (data) {
                if (data==1) {
                    parent.layer.msg('操作成功！', {icon: 1});
                    res = true;
                } else {
                    parent.layer.msg('操作失败：' + data.msg, {icon: 5});
                }
            },
            error: function (data) {
                parent.layer.msg('系统异常！', {icon: 1});
            }
        });
        return res;
    }

    function checkForm() {
        var name = $("#name").val();
        var parten = /^.{1,200}$/;//标题不能超过200个字
        if (!name.match(parten)) {
            parent.layer.msg('名称不能为空');
            return false;
        }
        return true;
    }

</script>
</body>
</html>
